/* Good IMF status duration model */

set more off 

use "c:\Data\Imf\IMFdata1.dta", clear

stset StateDur if particip==1, failure(StateChg) id(IMFid)
streg Quota USAID USODA oecd IMFQuota IMFUSAID IMFoecd IMFUSODA CPIL1  CPIL6  IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code) 

matrix b1=e(b)
matrix v1=e(V)
sca ll11=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code)  

matrix c1=e(b)
matrix w1=e(V)
sca ll12=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 numpart Partisan IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 IMFnump IMFParts CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat , dist(w) cluster(code) 

matrix d1=e(b)
matrix x1=e(V)
sca ll13=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 numpart Partisan seatlar pfall rfall IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 IMFnump IMFParts IMFseatl IMFpfall IMFrfall CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code) 

matrix e1=e(b)
matrix y1=e(V)
sca ll14=e(ll)

use "c:\Data\Imf\IMFdata2.dta", clear

stset StateDur if particip==1, failure(StateChg) id(IMFid)

streg Quota USAID USODA oecd IMFQuota IMFUSAID IMFoecd IMFUSODA CPIL1  CPIL6  IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code)  

matrix b2=e(b)
matrix v2=e(V)
sca ll21=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code)  

matrix c2=e(b)
matrix w2=e(V)
sca ll22=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 numpart Partisan IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 IMFnump IMFParts CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat , dist(w) cluster(code)  

matrix d2=e(b)
matrix x2=e(V)
sca ll23=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 numpart Partisan seatlar pfall rfall IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 IMFnump IMFParts IMFseatl IMFpfall IMFrfall CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1  IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code) 

matrix e2=e(b)
matrix y2=e(V)
sca ll24=e(ll)

use "c:\Data\Imf\IMFdata3.dta", clear

stset StateDur if particip==1, failure(StateChg) id(IMFid)

streg Quota USAID USODA oecd IMFQuota IMFUSAID IMFoecd IMFUSODA CPIL1  CPIL6  IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code)  

matrix b3=e(b)
matrix v3=e(V)
sca ll31=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code)  

matrix c3=e(b)
matrix w3=e(V)
sca ll32=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 numpart Partisan IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 IMFnump IMFParts CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat , dist(w) cluster(code)   

matrix d3=e(b)
matrix x3=e(V)
sca ll33=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 numpart Partisan seatlar pfall rfall IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 IMFnump IMFParts IMFseatl IMFpfall IMFrfall CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code) 

matrix e3=e(b)
matrix y3=e(V)
sca ll34=e(ll)

use "c:\Data\Imf\IMFdata4.dta", clear

stset StateDur if particip==1, failure(StateChg) id(IMFid)

streg Quota USAID USODA oecd IMFQuota IMFUSAID IMFoecd IMFUSODA CPIL1  CPIL6  IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code)  

matrix b4=e(b)
matrix v4=e(V)
sca ll41=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code)   

matrix c4=e(b)
matrix w4=e(V)
sca ll42=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 numpart Partisan IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 IMFnump IMFParts CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat , dist(w) cluster(code)   

matrix d4=e(b)
matrix x4=e(V)
sca ll43=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 numpart Partisan seatlar pfall rfall IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 IMFnump IMFParts IMFseatl IMFpfall IMFrfall CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code)

matrix e4=e(b)
matrix y4=e(V)
sca ll44=e(ll)

use "c:\Data\Imf\IMFdata5.dta", clear

stset StateDur if particip==1, failure(StateChg) id(IMFid)

streg Quota USAID USODA oecd IMFQuota IMFUSAID IMFoecd IMFUSODA CPIL1  CPIL6  IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code)  

matrix b5=e(b)
matrix v5=e(V)
sca ll51=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code)   

matrix c5=e(b)
matrix w5=e(V)
sca ll52=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 numpart Partisan IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 IMFnump IMFParts CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat , dist(w) cluster(code)  

matrix d5=e(b)
matrix x5=e(V)
sca ll53=e(ll)

streg Quota USAID USODA oecd FHdem ParlXel2 numpart Partisan seatlar pfall rfall IMFQuota IMFUSAID IMFoecd IMFUSODA IMFdem IMFParl2 IMFnump IMFParts IMFseatl IMFpfall IMFrfall CPIL1 CPIL6 IMFCPIL1 IMFCPIL6 CHDCL1 IMFCHDCL CHRSL1 IMFCHRSL IMFstat, dist(w) cluster(code) 

matrix e5=e(b)
matrix y5=e(V)
sca ll54=e(ll)

/* Model 1 */

matrix B4=b1\b2\b3\b4\b5
matrix row1=[1,1,1,1,1]
matrix B4mi=(B4'*row1')/5
mat V4mi=(v1+v2+v3+v4+v5)/5
mat Sqs=B4-row1'*B4mi'
mat A=Sqs[1, 1...]
mat AA=diag(A)
mat B=Sqs[2, 1...]
mat BB=diag(B)
mat C=Sqs[3, 1...]
mat CC=diag(C)
mat D=Sqs[4, 1...]
mat DD=diag(D)
mat E=Sqs[5, 1...]
mat EE=diag(E)

mat Sqsq=[A*AA\B*BB\C*CC\D*DD\E*EE]'*row1'

mat SE4sq=vecdiag(V4mi)'+(1/4)*Sqsq*(6/5)
mat SE4mi=(vecdiag(cholesky(diag(SE4sq))))'
mat final1=[B4mi, SE4mi]
mat colnames final1=Coeff StErr
noisily mat list final1

/*  Model 2  */

matrix B4=c1\c2\c3\c4\c5
matrix B4mi=(B4'*row1')/5
mat V4mi=(w1+w2+w3+w4+w5)/5
mat Sqs=B4-row1'*B4mi'
mat A=Sqs[1, 1...]
mat AA=diag(A)
mat B=Sqs[2, 1...]
mat BB=diag(B)
mat C=Sqs[3, 1...]
mat CC=diag(C)
mat D=Sqs[4, 1...]
mat DD=diag(D)
mat E=Sqs[5, 1...]
mat EE=diag(E)

mat Sqsq=[A*AA\B*BB\C*CC\D*DD\E*EE]'*row1'

mat SE4sq=vecdiag(V4mi)'+(1/4)*Sqsq*(6/5)
mat SE4mi=(vecdiag(cholesky(diag(SE4sq))))'
mat final2=[B4mi, SE4mi]
mat colnames final2=Coeff StErr
noisily mat list final2

/*  Model 3 */

matrix B4=d1\d2\d3\d4\d5
matrix B4mi=(B4'*row1')/5
mat V4mi=(x1+x2+x3+x4+x5)/5
mat Sqs=B4-row1'*B4mi'
mat A=Sqs[1, 1...]
mat AA=diag(A)
mat B=Sqs[2, 1...]
mat BB=diag(B)
mat C=Sqs[3, 1...]
mat CC=diag(C)
mat D=Sqs[4, 1...]
mat DD=diag(D)
mat E=Sqs[5, 1...]
mat EE=diag(E)

mat Sqsq=[A*AA\B*BB\C*CC\D*DD\E*EE]'*row1'

mat SE4sq=vecdiag(V4mi)'+(1/4)*Sqsq*(6/5)
mat SE4mi=(vecdiag(cholesky(diag(SE4sq))))'
mat final3=[B4mi, SE4mi]
mat colnames final3=Coeff StErr
noisily mat list final3

/*  Model 4 */

matrix B4=e1\e2\e3\e4\e5
matrix B4mi=(B4'*row1')/5
mat V4mi=(y1+y2+y3+y4+y5)/5
mat Sqs=B4-row1'*B4mi'
mat A=Sqs[1, 1...]
mat AA=diag(A)
mat B=Sqs[2, 1...]
mat BB=diag(B)
mat C=Sqs[3, 1...]
mat CC=diag(C)
mat D=Sqs[4, 1...]
mat DD=diag(D)
mat E=Sqs[5, 1...]
mat EE=diag(E)

mat Sqsq=[A*AA\B*BB\C*CC\D*DD\E*EE]'*row1'

mat SE4sq=vecdiag(V4mi)'+(1/4)*Sqsq*(6/5)
mat SE4mi=(vecdiag(cholesky(diag(SE4sq))))'
mat final4=[B4mi, SE4mi]
mat colnames final4=Coeff StErr
noisily mat list final4




